package com.sdhs.myproject.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.domain.R;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.SecurityUtils;
import com.sdhs.common.utils.poi.ExcelUtil;
import com.sdhs.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdhs.myproject.domain.GcMyprojectInformation;
import com.sdhs.myproject.service.IGcMyprojectInformationService;


/**
 * 我的项目--项目基本信息Controller
 *
 * @author andong
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/myproject/information")
public class GcMyprojectInformationController extends BaseController
{
    @Autowired
    private IGcMyprojectInformationService gcMyprojectInformationService;

    @Autowired
    private ISysDeptService iSysDeptService;

    /**
     * 查询我的项目--项目基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcMyprojectInformation gcMyprojectInformation)
    {
        List<GcMyprojectInformation> list = gcMyprojectInformationService.selectGcMyprojectInformationList(gcMyprojectInformation);
        return getDataTable(list);
    }

    /**
     * 查询我的项目--项目基本信息列表（无分页）
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:list')")
    @GetMapping("/findList")
    public AjaxResult findList(GcMyprojectInformation gcMyprojectInformation)
    {
        List<GcMyprojectInformation> list = gcMyprojectInformationService.selectAllProjectInformationList(gcMyprojectInformation);
        return success(list);
    }

    /**
     * 导出我的项目--项目基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:export')")
    @Log(title = "我的项目--项目基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcMyprojectInformation gcMyprojectInformation)
    {
        List<GcMyprojectInformation> list = gcMyprojectInformationService.selectGcMyprojectInformationList(gcMyprojectInformation);
        ExcelUtil<GcMyprojectInformation> util = new ExcelUtil<GcMyprojectInformation>(GcMyprojectInformation.class);
        util.exportExcel(response, list, "我的项目--项目基本信息数据");
    }

    /**
     * 获取我的项目--项目基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gcMyprojectInformationService.selectGcMyprojectInformationById(id));
    }
    
    /**
     * 根据项目id查询项目关联的合同列表
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:contract')")
    @GetMapping(value = "/selectContractByProjectId/{id}")
    public AjaxResult selectContractByProjectId(@PathVariable("id") Long id)
    {
        return success(gcMyprojectInformationService.selectContractByProjectId(id));
    }
    
    /**
     * 根据项目id查询项目关联的供应商列表
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:supplier')")
    @GetMapping(value = "/selectSupplierByProjectId/{id}")
    public AjaxResult selectSupplierByProjectId(@PathVariable("id") Long id)
    {
        return success(gcMyprojectInformationService.selectSupplierByProjectId(id));
    }

    /**
     * 根据当前登录人获取登录人权属单位
     */
    /*@PreAuthorize("@ss.hasPermi('myproject:information:select')")*/
    @GetMapping(value = "/selectCompanyIdtByUserId")
    public AjaxResult selectCompanyIdtByUserId()
    {
        String companyId = iSysDeptService.selectCompanyIdtByUserId(SecurityUtils.getDeptId());
        return success(iSysDeptService.selectDeptById(companyId));
    }
    /**
     * 新增我的项目--项目基本信息
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:add')")
    @Log(title = "我的项目--项目基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcMyprojectInformation gcMyprojectInformation)
    {
        return toAjax(gcMyprojectInformationService.insertGcMyprojectInformation(gcMyprojectInformation));
    }

    /**
     * 修改我的项目--项目基本信息
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:edit')")
    @Log(title = "我的项目--项目基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcMyprojectInformation gcMyprojectInformation)
    {
        return toAjax(gcMyprojectInformationService.updateGcMyprojectInformation(gcMyprojectInformation));
    }

    /**
     * 设置督办
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:supervise')")
    @Log(title = "我的项目--设置/取消督办", businessType = BusinessType.UPDATE)
    @PutMapping("/supervise")
    public AjaxResult supervise(@RequestBody GcMyprojectInformation gcMyprojectInformation)
    {
        return toAjax(gcMyprojectInformationService.markSupervise(gcMyprojectInformation));
    }
    /**
     * 删除我的项目--项目基本信息
     */
    @PreAuthorize("@ss.hasPermi('myproject:information:remove')")
    @Log(title = "我的项目--项目基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gcMyprojectInformationService.deleteGcMyprojectInformationByIds(ids));
    }
}
